﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace oLGame.Game.Items
{
    class Container : Item
    {
        protected List<Item> itemsInContainer = new List<Item>();
        protected double maxWeight, currentWeight;

        public Container()
        {
            Name = "Container";
            Value = 0;
            Lore = "This object looks like it could hold a few items.";
            MaximumWeight = 50;
        }

        public void AddItemToContainer(Item item)
        {
            if (item != null)
            { 
                // TODO: Check to see if max weight is exceeded
                Items.Add(item);
            }
        }

        public void RemoveItemFromContainer(Item item)
        {
            if (IsItemInContainer(item))
                Items.Remove(item);
        }

        public Item FindItemById(Item item)
        {
            Item result = itemsInContainer.Find(
                delegate(Item what)
                {
                    return what.EntityID == item.EntityID;
                }
            );
            return result;
        }

        public bool IsItemInContainer(Item item)
        {
            Item result = itemsInContainer.Find(
                delegate(Item what)
                {
                    return what.EntityID == item.EntityID;
                }
            );

            return (result != null);
        }

        public double ContentsWeight
        {
            get 
            {
                double weight = 0;
                // TODO: Add invalidation boolean for currentWeight only to run this loop when Items get added or removed from the container.
                foreach ( Item item in Items)
                {
                    weight += item.Weight;
                }

                return weight;
            }
        }

        public double MaximumWeight
        {
            get { return maxWeight; }
            set { maxWeight = value; }
        }

        new public double Weight
        {
            get { return currentWeight = ContentsWeight + itemWeight; }
            set { itemWeight = value; }
        }

        public List<Item> Items
        {
            get
            {
                return itemsInContainer;
            }

        }
    }
}
